const effectStatck=[]

 

function useEffect(callback){
    const excute=()=>{
        effectStatck.push(effect)
        try{
            callback()
        }finally{
            effectStatck.pop()
        }
        const effect={
            excute,
            deps:new Set()
        }
    }
    excute()
}
    
function useState(value){
    const subs=new Set()
    const getter=()=>{
        let effect=effectStatck[effectStatck.length-1]
        subscribe(effect,sub)
        // effect.deps.add()
    }
    const settter=(newValu)=>{
        value=newValue;
        for(const sub of [...subs]){
            sub.excute()
        }
    }
    return [getter,settter]
    // const setValue=(newValue)=>value=newValue
}
function subscribe(effect,subs){
    subs.add(effect)
    effect.deps.add(subs)
}